package com.irdstudio.efp.flow.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.efp.flow.service.dao.FlowWholeLifeCycleDao;
import com.irdstudio.efp.flow.service.domain.InstFlowEvent;
import com.irdstudio.efp.flow.service.facade.FlowWholeLifeCycleService;
import com.irdstudio.efp.flow.service.vo.FlowInstanceInfoVO;
import com.irdstudio.efp.flow.service.vo.InstFlowEventVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;

@Service("flowWholeLifeCycleService")
public class FlowWholeLifeCycleServiceImpl implements FlowWholeLifeCycleService, FrameworkService {
    
    private static Logger logger = LoggerFactory.getLogger(FlowWholeLifeCycleServiceImpl.class);

    @Autowired
    private FlowWholeLifeCycleDao flowWholeLifeCycle;
    
    @Override
    public List<FlowInstanceInfoVO> queryAllCurrLegalOrgDown(FlowInstanceInfoVO vo)  throws Exception {
        List<FlowInstanceInfoVO> vos = flowWholeLifeCycle.queryAllCurrLegalOrgDownByPage(vo);
        pageSet(vos, vo);
        return vos;
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<InstFlowEventVO> queryStageEventTree(String instFlowId) throws Exception {
        logger.info("根据流转实例编号："+ instFlowId +"查询阶段事件树开始......");
        List<InstFlowEventVO> eventVOs = null;
        try {
            List<InstFlowEvent> events = flowWholeLifeCycle.queryStageEventTree(instFlowId);
            eventVOs = (List<InstFlowEventVO>) beansCopy(events, InstFlowEventVO.class);
            logger.info("根据流转实例编号："+ instFlowId +"查询阶段事件树结束......");
        } catch (Exception e) {
            logger.error("根据流转实例编号："+ instFlowId +"查询阶段事件树出现异常!", e);
        }
        return eventVOs;
    }

}
